package model;

import java.awt.Color;

import controller.Spiel;

public class Transform {
	public FloatProperty vFaktor;
	public FloatProperty widthFaktor;
	public FloatProperty phi;
	public FloatProperty phiFaktor;
	public FloatProperty pointWinner;
	
	public boolean luecke;
	public Color circleColor;
	
	public Transform() {
		vFaktor = new FloatProperty(25f / Spiel.FPS, true);
		widthFaktor = new FloatProperty(1f, true);
		phi = new FloatProperty(0f, true);
		phiFaktor = new FloatProperty(25f / Spiel.FPS, false);
		pointWinner = new FloatProperty(0, true);
	}
	
	public void reset() {
		reset(false);
	}
	
	public void reset(boolean immediate) {
		vFaktor.reset(immediate);
		widthFaktor.reset(immediate);
		phi.reset(immediate);
		phiFaktor.reset(immediate);
		pointWinner.reset(immediate);
		
		luecke = false;
		circleColor = Color.YELLOW;
	}

	public void apply() {
		vFaktor.apply();
		widthFaktor.apply();
		phi.apply();
		phiFaktor.apply();
		pointWinner.apply();
	}
	
	public class FloatProperty {
		private static final float DEFAULT_SPEED = 0.1f;
		
		private float value;
		private float targetValue;
		private float defaultValue;
		private boolean animate;
		private float speed = FloatProperty.DEFAULT_SPEED;
		
		public FloatProperty(float defaultValue, boolean animate) {
			this.defaultValue = defaultValue;
			this.animate = animate;
		}
		
		public void reset(boolean immediate) {
			targetValue = defaultValue;
			if (immediate)
				value = targetValue;
		}
		
		public void set(float value) {
			targetValue = value;
		}
		
		public void add(float value) {
			targetValue += value;
		}
		
		public void sub(float value) {
			targetValue -= value;
		}
		
		public void mul(float value) {
			targetValue *= value;
		}
		
		public float getTarget() {
			return targetValue;
		}
		
		public void apply() {
			if (animate)
				value = value - (value - targetValue) * speed;
			else
				value = targetValue;
		}
		
		public float getValue() {
			return value;
		}
		
		public void setValue(float value) {
			this.value = value;
			targetValue = value;
		}
	}
}
